package net.lahuobao.finance.service.impl.reccode;

import net.lahuobao.finance.dao.RecCode_UserDaoMapper;
import net.lahuobao.finance.entity.reccode.ReccodeEntity;
import net.lahuobao.finance.entity.reccode.UserRecCodeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.lahuobao.finance.service.reccode.ReccodeServiceI;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;

import java.util.List;
import java.util.Map;

@Service("reccodeService")
@Transactional
public class ReccodeServiceImpl extends CommonServiceImpl implements ReccodeServiceI {

    @Autowired
    private RecCode_UserDaoMapper recCodeDao;

    @Override
    public List<UserRecCodeEntity> users(Map<String, Object> params) {

        return recCodeDao.users(params);
    }

    @Override
    public int usersCount(Map<String, Object> params) {

        return recCodeDao.usersCount(params);
    }

    /***
     *
     * 查询出当前级别的最大的邀请码
     * @return	String 邀请码
     */
    public synchronized int getMaxRecCode(){
        String sql = "select max(rec_code) as maxCode from t_s_rec_code";
        Map<String,Object> result = commonDao.findOneForJdbc(sql);
        if(result == null || result.get("maxCode") == null){
            return 0;
        }else{
            return Integer.parseInt(result.get("maxCode").toString());
        }
    }


    @Override
    public ReccodeEntity getByUserId(String id) {

        return recCodeDao.getByUserId(id);
    }


    @Override
    public List<UserRecCodeEntity> usersAll(Map<String, Object> params) {

        return recCodeDao.usersAll(params);
    }

    @Override
    public int usersAllCount(Map<String, Object> params) {

        return recCodeDao.usersAllCount(params);
    }
}